package com.zeroup.auto.assists.step.unify;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.util.Log;

import androidx.annotation.NonNull;

import com.ven.assists.stepper.StepData;
import com.zeroup.auto.assists.next.StepBeanData;
import com.zeroup.auto.utils.AssistsUtils;
import com.ven.assists.Assists;
import com.ven.assists.stepper.StepCollector;
import com.ven.assists.stepper.StepImpl;

public class StartAppStep extends StepImpl {
    @Override
    public void onImpl(@NonNull StepCollector stepCollector) {
        stepCollector.next(1,false,(i,c)->{
            Object serviceData = AssistsUtils.getServiceData(i.getData());
            if(serviceData==null){
                return AssistsUtils.nextStep(i.getData());
            }
            if(serviceData instanceof StepBeanData) {
                StepBeanData stepBeanData = (StepBeanData) serviceData;
                // 获取PackageManager实例
                PackageManager packageManager = Assists.getService().getPackageManager();

                // 创建一个Intent，用于启动应用
                Intent intent = packageManager.getLaunchIntentForPackage(stepBeanData.getDataValue());
                assert Assists.getService() != null;
                Assists.getService().startActivity(intent);
            }
            Log.d("StartAppStep===>","启动");
            return AssistsUtils.nextStep(i.getData());
        });
    }
}
